/**
 * Created by cj on 2017/5/7.
 */

var addMyEvent = function (el,ev,fn) {
    if(el.addEventListener){
        el.addEventListener(ev,fn,false);
    }else if(el.attachEvent){
        el.attachEvent("on"+ev,fn);
    }else{
        el["on"+ev]=fn;
    }
};
//使用
addMyEvent(document.getElementById("div1"),"click",function(){ alert(123); });